package com.yetm.springbootdemo.config;

import com.yetm.springbootdemo.quartz.QuartzDemo;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail printJobDetail() {
        //绑定具体工作
        return JobBuilder.newJob(QuartzDemo.class).storeDurably().build();
    }

    @Bean
    public Trigger printTrigger() {
        //绑定对应的工作明细
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/2 * * * * ?");
        return TriggerBuilder.newTrigger().forJob(printJobDetail()).withSchedule(scheduleBuilder).build();
    }
}
